#!/bin/bash
# Check that all support PC mounts are ok, and mount them if not.
MOUNT_DIR="/usr/local/microtardis/harvest/new/mnt/rmmf_supportpc";
PING="/sbin/ping"

function domount {
    NETWORK_PATH=$1;
    HOST=$2;
    MOUNT_NAME=$3;

    if [ "`ls -A ${MOUNT_DIR}/${MOUNT_NAME}`" ]; then
	    ./set_status.sh ${MOUNT_NAME} up "${MOUNT_NAME} already mounted - ok."
        return 
    fi
    echo "Mounting ${MOUNT_NAME}: ";
    # Ping first so we fail much faster if machine is down.
    ${PING} -q -c 1 -t 5 ${HOST} > /dev/null;
    if [ $? -ne 0 ]; then
	   ./set_status.sh ${MOUNT_NAME} down "${MOUNT_NAME} machine (${HOST}) is unreachable."
    else 
       # skipping the actual mount!
       #mount_smbfs -o rdonly "${NETWORK_PATH}" "${MOUNT_DIR}/${MOUNT_NAME}"
     
     ./set_status.sh ${MOUNT_NAME} up "${MOUNT_NAME} is reachable."
     return
     echo "Skipping mount."      
     if [ $? -ne 0 ]; then
 	     ./set_status.sh ${MOUNT_NAME} down "Failed to mount ${MOUNT_NAME} even though host (${HOST}) is reachable."
	   else
		  ./set_status.sh ${MOUNT_NAME} up "Mounted ${MOUNT_NAME} as read-only."
       fi          
     fi
}

domount "//supervisor:supervisor@192.168.10.24/Users%20Images" "192.168.10.24" "Quanta200"
domount "//supervisor:supervisor@192.168.10.23/SharedData" "192.168.10.23" "NovaNanoSEM"
